import { fileURLToPath, URL } from 'node:url'
// 按需el引入
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'



import { defineConfig,loadEnv } from 'vite'
// 引入
import VitePluginExtend from "vite-plugin-vue-setup-extend"
import vue from '@vitejs/plugin-vue'
// https://vitejs.dev/config/
export default defineConfig((ENV) => {
  // console.log(ENV);
  // const env = loadEnv( ENV.mode , __dirname);
  // console.log(env)
  return {
    plugins: [
      vue(),
      VitePluginExtend(),
      AutoImport({
        resolvers: [ElementPlusResolver()]
      }),
      Components({
        resolvers: [ElementPlusResolver()]
      })
    ],
    build: {
      rollupOptions: {
        output: {
          // 在这里修改静态资源路径
          chunkFileNames: 'assets/js/[name]-[hash].js',
          entryFileNames: 'assets/js/[name]-[hash].js',
          assetFileNames: 'assets/[ext]/[name]-[hash].[ext]',
        }
      }
    },
    // 清除控制台打印
    esbuild: {
      drop: ENV.mode === 'production' ? ['console', 'debugger'] : []
    },
    base: './', // 这里更改打包相对绝对路径
    server: {
      host: '0.0.0.0',
      port: 9528,
      strictPort: false,
      proxy: {
        // 代理路径
        '/yuku/api/screen': {
          target: 'http://192.168.3.37:8808',
          // target: 'http://192.168.3.37:8808',
          // target: 'https://test.yukukeji.com',
          // target: 'https://www.yukukeji.com',
          // 是否改变请求的源地址，这里设置为 true，表示强制使用绝对路径
          changeOrigin: true,
        }
      }
    },
    resolve: {
      alias: {
        '@': fileURLToPath(new URL('./src', import.meta.url))
      }
    }
  }
})
